﻿import { Component, Injector, ViewChild ,Input} from '@angular/core';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import * as _ from 'lodash';
import { finalize } from 'rxjs/operators';
import { Tab } from './tab.model';
import { Paginator } from 'primeng/components/paginator/paginator';
import { Table } from 'primeng/components/table/table';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import { RequirementGetTabEditComponent } from './requirement-get-tab_edit.component'
import { PrimengTableHelper } from '@shared/helpers/PrimengTableHelper';
import { UsingFormServiceProxy, UsingFormDetailDto } from '@shared/service-proxies/service-proxies';
import { TestDataServiceProxy ,RequirementsForModelComponentDto,UsingFormState} from '@shared/service-proxies/service-proxies';

@Component({
    selector: 'requirementGetTabComponent',
    templateUrl: './requirement-get_tab.component.html',
    styleUrls: ['./requirement-get_tab.component.less'],
    animations: [appModuleAnimation()]
})
export class RequirementGetTabComponent extends AppComponentBase{
    @ViewChild('requirementGetTabEditComponent') requirementGetTabEditComponent: RequirementGetTabEditComponent;
    @ViewChild('dataTable') dataTable: Table;
    @ViewChild('paginator') paginator: Paginator;
    primengTableHelpers: Array<PrimengTableHelper>;
    tabs: Array<Tab>;
    tabObject:{
        filterText:""
    };
    loading = false;
    caches: any = null;
    logs: any = '';
    filterText = '';

    active =false;
    hidden=true;
    title:"hello";
    @Input() usingFormDto: RequirementsForModelComponentDto;
    

    constructor(
        injector: Injector,
        private _usingFormServiceProxy: UsingFormServiceProxy,
        private _testDataServiceProxy: TestDataServiceProxy) {
        super(injector);
        this.active = false;
    }
    addTab(usingFormDetailDto: UsingFormDetailDto): void {
        this.active = true;
    }

    setRequirementPackage(_pUsingFormDto: RequirementsForModelComponentDto): void {
        this.usingFormDto = _pUsingFormDto;
    }
    getRequirements( tab:Tab,event?: LazyLoadEvent) {
        this.primengTableHelper.showLoadingIndicator();
    }
    receive():void{

    }
    
    /**
    * 检索需求详细
    * @param requirementItemDto 
    */
    getRequirementItems(event?: LazyLoadEvent) {
        if (this.primengTableHelper.shouldResetPaging(event)) {
            this.paginator.changePage(0);
            return;
        }
        this.primengTableHelper.showLoadingIndicator();
        this._usingFormServiceProxy.getAllUsingDetails(
            undefined,//state
            undefined,//startuser 领用人 看谁的
            undefined, //currenthandle 谁负责的
            this.filterText,
            this.primengTableHelper.getSorting(this.dataTable),
            this.primengTableHelper.getMaxResultCount(this.paginator, event),
            this.primengTableHelper.getSkipCount(this.paginator, event)
        ).pipe(finalize(() => this.primengTableHelper.hideLoadingIndicator())).subscribe(result => {
                this.primengTableHelper.totalRecordsCount = result.items.length;
                this.primengTableHelper.records = result.items;
                this.primengTableHelper.hideLoadingIndicator();
            });
    }
    toCheckLink(usingFormDetailDto:UsingFormDetailDto):void{
        this.requirementGetTabEditComponent.show(usingFormDetailDto.id);
    }
    getState(value):string{
        return UsingFormState[value];
    }
    /**
     * 删除需求详细
     * @param requirementItemDto 
     */
    deleteRequirementItems(usingFormDetailDto:UsingFormDetailDto){
        this.message.confirm(
            '删除该需求？',
            this.l('AreYouSure'),
            (isConfirmed) => {
                if (isConfirmed) {
                    this._usingFormServiceProxy.deleteDetailOfForm(usingFormDetailDto.id)
                    .pipe(finalize(() => { this.getRequirementItems();}))
                    .subscribe(() => {
                        this.notify.info(this.l('DeletedSuccessfully'));
                    });
                }
            }
        );
    }
    reloadPage():void {
        var ddd ='';
    }

    onResize(event): void {
        
    }

    ngOnInit(): void {
        const self = this;
    }
}
